import { stringify } from 'qs';
import request from '../utils/request';

export async function addPlace(payload) {
  return request(`/gamePlace/`, {
    method: 'POST',
    body: payload,
  });
}

export async function modifyPlace(payload) {
  return request(`/gamePlace/`, {
    method: 'PATCH',
    body: payload,
  });
}

export async function deletePlace(id) {
  return request(`/gamePlace/${id}`, {
    method: 'DELETE',
  });
}

export async function findPlaceForGame(gameCode) {
  return request(`/gamePlace/?gameCode=${gameCode}`, {
    method: 'GET',
  });
}

export async function findTimeForGame(params) {
  const { zubieCode } = params;
  return request(`/gameZubiePlace/?zubieCode=${zubieCode}`, {
    method: 'GET',
    headers: { 'x-sort-by': 'seq' },
  });
}

export async function findPlaceColumns(zubieCode) {
  return request(`/gameZubiePlace/columns?zubieCode=${zubieCode}`, {
    method: 'GET',
  });
}

export async function findZhixuForKongchang(params) {
  const { zubieCode } = params;
  return request(`/gameSchedule/queryZhixuForKongchang/${zubieCode}`, {
    method: 'GET',
  });
}

export async function findPlaceData(params) {
  const { gameId, headers } = params;
  return request(`/gameZubiePlace/datas?gameId=${gameId}`, {
    // headers: headers?headers:{'x-page-num': 1,
    //   'x-page-size': 20},
    method: 'GET',
  });
}

export async function patchAddZubiePlace(payload) {
  return request(`/gameZubiePlace/patchAdd`, {
    method: 'POST',
    body: payload,
  });
}

export async function findGameCaipan(gameCode) {
  return request(`/gameCaipan/findGameCaipan?gameCode=${gameCode}`, {
    method: 'GET',
  });
}

export async function findCaipanByTel(tel) {
  return request(`/gameCaipan/findCaipanByTel?tel=${tel}`, {
    method: 'GET',
  });
}

export async function addCaipan(payload) {
  const { gameCode, code, caipanRole } = payload;
  return request(
    `/gameCaipan/addCaipan?gameCode=${gameCode}&userCode=${code}&caipanRole=${caipanRole}`,
    {
      method: 'POST',
    }
  );
}

export async function deleteCaipan(payload) {
  const { gameCode, code, caipanRole } = payload;
  return request(`/gameCaipan/removeCaipan?gameCode=${gameCode}&userCode=${code}`, {
    method: 'DELETE',
  });
}

export async function setCaipan(payload) {
  const { matchCode, caipanCode, caipanRole } = payload;
  return request(
    `/gameCaipan/setCaipan?matchCode=${matchCode}&caipanCode=${caipanCode}&caipanRole=${caipanRole}`,
    {
      method: 'PATCH',
    }
  );
}

export async function queryMatchCaipan(payload) {
  const { matchCode, caipanCode, caipanRole } = payload;
  return request(`/gameCaipan/findMatchCaipan/${matchCode}`, {
    method: 'GET',
  });
}
